package org.datascooter.impl;

import org.datascooter.exception.DataScooterException;
import org.datascooter.inface.IDataManager;
import org.datascooter.inface.ISnipListener;
import org.datascooter.utils.SnipUtils;

/**
 * Purpose for listening an actions with data
 * 
 * @author nemo
 * 
 */
public class DefaultSnipListener implements ISnipListener {

	protected IDataManager manager;

	public DefaultSnipListener(IDataManager manager) {
		this.manager = manager;
	}

	@Override
	public void snipExecuted(DataSnip dataSnip) {
		try {
			SnipUtils.rebuildId(dataSnip);
			manager.getSnipManager().execute(manager.getBuilderInt().build(manager.getInstanceManager().flush(dataSnip), manager.getTransactionId()));
		} catch (Exception e) {
			throw new DataScooterException(e);
		}
	}
}
